package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.*;
	
	public class ColorAction extends AbstractAction
	{
		private var matrix:ColorMatrix = new ColorMatrix();
		private var brightness:Number = 0;
		private var contrast:Number = 0;
		private var sat:Number = 0;
		private var hue:Number = 0;
		
		public function setValue(b:Number, c:Number, s:Number, h:Number):ColorAction
		{
			this.brightness = b;
			this.contrast = c;
			this.sat = s;
			this.hue = h;
			this.matrix.reload();
			this.matrix.adjustBrightness(b);
			this.matrix.adjustContrast(c);
			this.matrix.adjustSaturation(s);
			this.matrix.adjustHue(h);
			
			return this;
		}
		
		public override function getDescription():String
		{
			return "Color (" + this.brightness.toFixed(1) + ", " + this.contrast.toFixed(1) + ", " +
				this.sat.toFixed(1) + ", " + this.hue.toFixed(1) + ")";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix.matrix);
			ret.applyFilter(ret, ret.rect, new Point(0, 0), filter);
			return ret;
		}	
	}
}